package main

import (
	"./events"
	"./luahelper"
	"./registers"
	lua "github.com/yuin/gopher-lua"
	"log"
)

type Fraction struct {
	SCO  float64
	Name string
}

type TestStruct struct {
	Fraction Fraction
	Name     string
	PassWord string
	Age      int
}

func main() {
	l := lua.NewState()

	done := make(chan int, 10)
	RegisterFunc_4lua(l, done)
	registers.RegisterAllFunc_4lua(l)

	luahelper.All_RegisterFunc = registers.RegisterAllFunc_4lua

	log.Println("do main.lua")
	err := l.DoFile("main.lua")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("do main.lua finsh & wait exit")

	events.Trigger("InitFinsh")

	<-done

	events.Trigger("Exit")

	log.Println("Run Finsh")
}

func RegisterFunc_4lua(l *lua.LState, done chan int) {
	l.SetGlobal("Exit", l.NewFunction(func(lState *lua.LState) int {
		done <- 0
		return 0
	}))
}
